// 应用生命周期观察者
import 'package:concierge/app/common/common.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class AppLifecycleObserver extends WidgetsBindingObserver {
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);

    switch (state) {
      case AppLifecycleState.resumed:
        print('应用从后台进入前台');
        // 应用从后台进入前台时，执行一次自动连接并刷新定时器
        break;
      case AppLifecycleState.paused:
        print('应用进入后台');
        break;
      case AppLifecycleState.inactive:
        print('应用处于非活跃状态');
        break;
      case AppLifecycleState.detached:
        print('应用被分离');
        break;
      case AppLifecycleState.hidden:
        print('应用被隐藏');
        break;
    }
  }

  @override
  void didChangeLocales(List<Locale>? locales) {
    if (locales != null && locales.isNotEmpty) {
      var languageCode = changeLanguage(locales.first, 0);
      String countryCode = locales.first.countryCode ?? 'US';
      print('语言切换 end: languageCode:$languageCode   countryCode:$countryCode');
      Get.updateLocale(Locale(languageCode, countryCode));
    }
  }
}
